package com.huage_07.lesson_06;

import java.io.*;

public class ObjectOutputStreamDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {

        write();
        read();
    }
    //序列化
    public static void write()throws IOException, ClassNotFoundException{
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("class1\\src\\com\\huage_07\\lesson_06\\Student.txt"));

        Student std = new Student("张三",23);

        oos.writeObject(std);

        oos.close();
    }
    //反序列化
    public static void read()throws IOException, ClassNotFoundException{
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("class1\\src\\com\\huage_07\\lesson_06\\Student.txt"));

        Object o = ois.readObject();
        Student std1 = (Student) o;
        String name = std1.getName();
        int age = std1.getAge();
        System.out.println(name+","+age);
    }
}
